package com.FengChaoSystem.service.CourierService;

import com.FengChaoSystem.dao.CourierDao;
import com.FengChaoSystem.pojo.Occupy;
import com.FengChaoSystem.pojo.Order;
import com.FengChaoSystem.pojo.PageNeed;
import com.FengChaoSystem.pojo.User;
import com.FengChaoSystem.service.CourierImpl;
import com.FengChaoSystem.untils.SqlSessionFactoryUtils;
import com.Mybatis.session.SqlSession;
import com.Mybatis.session.SqlSessionFactory;

import java.util.List;

import static cn.hutool.poi.excel.sax.ElementName.c;

public class CourierService implements CourierImpl {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public List<Order> selectAllCanSendOrderByCondition(PageNeed pageNeed) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectAllCanSendOrderByCondition(pageNeed);
        sqlSession.close();
        return orders;
    }

    @Override
    public List<Order> selectAllCanSendOrder() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectAllCanSendOrder();
        sqlSession.close();
        return orders;
    }

    @Override
    public List<Order> selectSendingOrderByCondition(PageNeed pageNeed) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectSendingOrderByCondition(pageNeed);
        sqlSession.close();
        return orders;
    }

    @Override
    public List<Order> selectSendingOrder(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectSendingOrder(user);
        sqlSession.close();
        return orders;
    }

    @Override
    public List<Order> selectAllOrderByCondition(PageNeed pageNeed) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectAllOrderByCondition(pageNeed);
        sqlSession.close();
        return orders;
    }

    @Override
    public List<Order> selectAllOrder(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Order> orders = mapper.selectAllOrder(user);
        sqlSession.close();
        return orders;
    }

    @Override
    public void acceptOrder(Order order) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        mapper.acceptOrder(order);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<Occupy> selectAllOccupy1() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Occupy> occupies = mapper.selectAllOccupy1();
        sqlSession.close();
        return occupies;
    }

    @Override
    public List<Occupy> selectAllOccupy2() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Occupy> occupies = mapper.selectAllOccupy2();
        sqlSession.close();
        return occupies;
    }

    @Override
    public List<Occupy> selectAllOccupy3() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        List<Occupy> occupies = mapper.selectAllOccupy3();
        sqlSession.close();
        return occupies;
    }

    @Override
    public void addOccupy(Occupy occupy) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        mapper.addOccupy(occupy);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Occupy hasGetWord(Occupy occupy) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        Occupy result = mapper.hasGetWord(occupy);
        sqlSession.close();
        return result;
    }

    @Override
    public Order hasBeAccept(Order target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CourierDao mapper = sqlSession.getMapper(CourierDao.class);
        Order order = mapper.hasBeAccept(target);
        sqlSession.close();
        return order;
    }
}
